1189A - Keanu Reeves - CodeForces Solution


strings *800

Please click on ads to support us..

Python Code:


n = input()
s = input()
count_1 = 0
count_0 = 0
for i in s:
    if i == "1":
        count_1 += 1
    else:
        count_0 += 1

if count_1 == count_0:
    print(2)
    print(s[0] + " " + s[1:])
else:
    print(1)
    print(s)


C++ Code:

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 110;

bool dp[MAXN][MAXN];
int last[MAXN][MAXN];
int s[MAXN];
char c[MAXN];

void printans(int k, int n){
    if(n == 0) return;
    int j = last[k][n];
    printans(k - 1, j - 1);
    for(int i = j; i <= n; i++){
        printf("%d", s[i]);
    }
    printf(" ");
}

int main(){
    int n; scanf("%d", &n);
    scanf(" %s", c);
    for(int i = 0; i < n; i++){
        s[i + 1] = c[i] - '0';
    }

    for(int i = 0; i <= n; i++) dp[i][i] = true;

    for(int i = 1; i <= n; i++){
        for(int k = 1; k <= i; k++){
            int qtd0 = 0, qtd1 = 0;
            for(int j = i; j >= 1; j--){
                if(s[j] == 0) qtd0++;
                if(s[j] == 1) qtd1++;
                if(qtd0 == qtd1) continue;
                if(dp[k - 1][j - 1]){
                    dp[k][i] = true;
                    last[k][i] = j;
                    break;
                }
            }
        }
    }

    for(int k = 1; k <= n; k++){
        if(dp[k][n]){
            printf("%d\n", k);
            printans(k, n);
            return 0;
        }
    }
}
 	  	  			 	 	    	   	  	  			


Comments

Submit
0 Comments
More Questions

151A - Soft Drinking
1352A - Sum of Round Numbers
281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother